<%@ page language="java" contentType="text/html; charset=UTF-8" 
import="com.google.appengine.api.datastore.KeyFactory,java.util.*,org.windblog.core.entity.*,org.windblog.core.*"  pageEncoding="UTF-8"%>
<%
	String mnp     = request.getParameter("message");
	int messageNum = 0;
	if(mnp!=null)
		messageNum = Integer.parseInt(mnp);
	String message = null;
	switch(messageNum){
		case 1  : message = "创建页面失败.";break;
		case 2  : message = "创建页面成功.";break;
		case 3  : message = "删除页面成功.";break;
		case 4  : message = "删除页面失败.";break;
		case 5  : message = "修改页面失败.";break;
		case 6  : message = "修改页面成功.";break;
		default : message = null;
	}
	
	Page root = PageService.getRoot() ;  
	Stack<Page> pageStack = new Stack<Page>();
	Stack<Integer> levelStack = new Stack<Integer>();
	int curLevel = -1;
	pageStack.push(root);
	levelStack.push(curLevel);
%>
<%!
	String printLine(int num)
	{
		StringBuilder sb = new StringBuilder("");
		for(int i=0;i<num;i++)
		{
			sb.append("&nbsp;-&nbsp;");
		}
		return sb.toString();
	}
%>
		<jsp:include page="header.jsp"></jsp:include>
		<jsp:include page="sidebar.jsp"></jsp:include>
		<script type="text/javascript">
			$(function(){
				// Accordion
				$("#accordion").accordion("activate",3);
				$("#pages_edit").prepend(">");
			});
		</script>
		<div id="content">
			<h2>Edit Pages</h2>
			<hr/>
			<% if(message!=null){%>
			<div class="ui-widget" style="width:50em">
			<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
				<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
				<%=message%>
				</p>
			</div>
			</div><br/>
			<%} 
			%>
			<div id="postspanel" class="ui-widget ui-widget-content ui-corner-all" style="margin-top:10px;padding:0;width:800px"> 
			<h3 class="ui-widget-header" style="padding:5px 10px;font-size:12px;">Posts</h3>
				<table id="pages" border="1" cellspacing="0" style="width:100%">
					<thead>
					<tr>
						<th style="width:60%">Title</th>
						<th style="width:20%">Author</th>
						<th style="width:20%">Date</th>
					</tr>
					</thead>
					<%
						
						if(root!=null)
						{
							while(!pageStack.empty())
							{
								Page currentPage = pageStack.pop();
								curLevel = levelStack.pop();
								if(!currentPage.isRoot()){
								%>
								<tr  class="mzone">
									<td><strong><a href="<%=currentPage.getEditLink() %>"><%=printLine(curLevel)+currentPage.getTitle() %> </a></strong><div>&nbsp;<span class="Action" style="display:none"><a href="<%=currentPage.getEditLink() %>">Edit</a>|<a href="<%=currentPage.getDeleteLink() %>">Delete</a>|<a href="<%=currentPage.getPermalink() %>">View</a></span></div></td>
									<td><%=currentPage.getAuthor() %></td>
									<td><%=currentPage.getFormatedDate() %></td>
								</tr>
											<%}
								List<Page> childPages = new LinkedList<Page>(currentPage.getChildPages());
								Collections.sort(childPages);
								for(Page p : childPages){
									pageStack.push(p);
									levelStack.push(curLevel+1);
								}
								
							}//end while
						}//end if
					%>
				</table>
			</div> 
		</div>
		<jsp:include page="footer.jsp"></jsp:include>
